import axios from "axios";
import {BASE_URL, TIMEOUT} from "./config";

const instance = axios.create({
  baseURL: BASE_URL,
  timeout: TIMEOUT,
  headers: {'Content-Type': 'multipart/form-data'}
})

instance.interceptors.request.use((config) => {
  console.log('拦截操作');
  return config;
}, error => {
  return error;
})

instance.interceptors.response.use((res) => {
  return res;
}, error => {
  if(error && error.response) {
    switch (error.response.status) {
      case 400:
        console.log('请求错误')
        break
      case 401:
        console.log('未认证')
        break
      default:
        console.log('其他信息错误')
    }
  }
})

export default instance;